package com.example.activiti.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.history.HistoricProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.activiti.dto.publicDto.ActivitiResponseDto;
import com.example.activiti.service.HistoryManagerService;
import com.example.activiti.service.ShowProcessService;

@RestController  
@RequestMapping("historyManagerController")
public class HistoryManagerController {
	@Autowired
	private HistoryManagerService historyManagerService;
	@Autowired
	private ShowProcessService showProcessService;
	
	/**
     * complateQingjia
     * 流程历史查询
     * @param paramMap 是左右的参数
     */
    @PostMapping("getIdentityByCreateUser")
	public List<HistoricProcessInstance> getIdentityByCreateUser(String assignee){
		return historyManagerService.getIdentityByCreateUser(assignee);
	}
    
    /**
	 * 获取所有的正常存活的未结束或删除的流程实例
	 * @return
	 */
    @PostMapping("getAllSurvivalInstance")
	public List<ActivitiResponseDto> getAllSurvivalInstance(){
		//TODO 需要传递分页信息和其他的一些条件
		return historyManagerService.getAllSurvivalInstance();
	}
    
    /**
	 * 根据流程实例获取已经审批的所有的任务
	 */
    @PostMapping("getInstanceInUser")
	public UserTask getInstanceInUser(String istanceId) {
		return historyManagerService.getInstanceInUser(istanceId);
	}
    /** 显示流程图
	 * @param request
	 * @param deploymentId 流程图的唯一编号
	 * @param instanceId 流程实例编号
	 * @throws UnsupportedEncodingException 
	 */
    @GetMapping("displayFlowCurrPicnew")
	public void displayFlowCurrPicnew(String deploymentId, String instanceId,HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{
		showProcessService.displayFlowCurrPicnew(deploymentId, instanceId, request, response);
	}
}
